<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
            <el-form-item label="订单号" prop="orderNo">
                <el-input v-model="queryParams.orderNo" placeholder="请输入订单号" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="状态" prop="status">
                <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
                    <el-option v-for="(item, index) in statusOptions" :key="index" :label="item.label"
                        :value="item.value" />
                </el-select>
            </el-form-item>
            <el-form-item label="看房时间" prop="bookingTime">
                <el-date-picker clearable size="small" style="width: 200px" v-model="queryParams.bookingTime"
                    type="date" value-format="yyyy-MM-dd" placeholder="选择看房时间">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="订单号" align="center" prop="orderNo" min-width="140" />
            <el-table-column label="姓名" align="center" prop="fullName" />
            <el-table-column label="手机号" align="center" prop="phone" />
            <el-table-column label="定金金额" align="center" prop="depositPrice" />
            <el-table-column label="已退定金" align="center" prop="refundDepositPrice" />
            <el-table-column label="状态" align="center" prop="status">
                <template slot-scope="scope">
                    <div v-for="(item, index) in statusOptions" :key="index">
                        <el-tag v-if="item.value == scope.row.status" :type="item.type">{{ item.label }}</el-tag>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="门锁密码" align="center" prop="temporaryPwd" />
            <el-table-column label="看房时间" align="center" prop="bookingTime" min-width="120" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-refresh-left" @click="handleRefund(scope.row)"
                        v-hasPermi="['order:info:refund']">退款</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />

        <!-- 添加或修改支付订单信息对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="金额" prop="money">
                    <el-input type="number" v-model="form.money" placeholder="请输入金额" />
                </el-form-item>
                <el-form-item label="描述">
                    <el-input type="textarea" v-model="form.money" placeholder="请输入描述" />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { listInfo, getInfo, addInfo, updateInfo, exportInfo } from "@/api/order/info";

export default {
    name: "Info",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 总条数
            total: 0,
            // 支付订单信息表格数据
            infoList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                orderNo: undefined,
                orderType: 'zfyd_order',
                merchantOrderNo: undefined,
                status: undefined,
                wxClientId: undefined,
                payStatus: undefined,
                payTime: undefined,
                payType: undefined,
                wxUserId: undefined,
                totalAmount: undefined,
                payAmount: undefined
            },
            statusOptions: [
                // { value: '0', label: '待审核', type: 'warning' },
                { value: '1', label: '预定成功', type: 'success' },
                { value: '2', label: '取消', type: 'info' },
                // { value: '3', label: '驳回', type: 'danger' },
                { value: '5', label: '已完成', type: 'success' },
            ],
            // 表单参数
            form: {},
            // 表单校验
            rules: {
            }
        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询支付订单信息列表 */
        getList() {
            this.loading = true;
            listInfo(this.queryParams).then(response => {
                this.infoList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: undefined,
                orderNo: undefined,
                orderType: 'zfyd_order',
                merchantOrderNo: undefined,
                status: "0",
                delFlag: undefined,
                createBy: undefined,
                createTime: undefined,
                updateBy: undefined,
                updateTime: undefined,
                wxClientId: undefined,
                payStatus: "0",
                payTime: undefined,
                payType: undefined,
                wxUserId: undefined,
                totalAmount: undefined,
                payAmount: undefined
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加支付订单信息";
        },
        /** 修改按钮操作 */
        handleRefund(row) {
            this.reset();
            const id = row.id || this.ids
            getInfo(id).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "租房预定退押金";
            });
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != undefined) {
                        updateInfo(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess("修改成功");
                                this.open = false;
                                this.getList();
                            }
                        });
                    } else {
                        addInfo(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess("新增成功");
                                this.open = false;
                                this.getList();
                            }
                        });
                    }
                }
            });
        },
        /** 导出按钮操作 */
        handleExport() {
            const queryParams = this.queryParams;
            this.$confirm('是否确认导出所有支付订单信息数据项?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return exportInfo(queryParams);
            }).then(response => {
                this.download(response.msg);
            }).catch(function () { });
        }
    }
};
</script>